package com.edu.test;


import com.edu.bean.*;
import com.edu.mapper.BookMapper;
import com.edu.mapper.EmpMapper;
import com.edu.mapper.GradeMapper;
import com.edu.mapper.TypeMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class MyTest04 {

    private SqlSession sqlSession = null;

    @Before
    public void init() throws IOException {
        String path = "mybatis-config.xml";

        InputStream inputStream = Resources.getResourceAsStream(path);

        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        sqlSession = sqlSessionFactory.openSession();
    }

    @Test
    public void test(){
        BookMapper bookMapper = sqlSession.getMapper(BookMapper.class);
        Book book = bookMapper.selectBookById(1);
        System.out.println(book);
        for (Type type : book.getTypeList()) {
            System.out.println(type);
        }
    }

    @Test
    public void test5(){
        TypeMapper typeMapper = sqlSession.getMapper(TypeMapper.class);
        Type type = typeMapper.selectTypeById(4);
        System.out.println("本次查找的类型信息:");
        System.out.println(type);
        System.out.println("该类型的书包括");
        for (Book book : type.getBookList()) {
            System.out.println(book);
        }

    }



}
